package com.hsh.erp.domain.file;

import com.hsh.erp.constants.filepath.FileSuffer;
import com.hsh.erp.enums.FileEnum;
import com.hsh.erp.utils.DateUtils;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.logging.log4j.util.Strings;

@Data
@NoArgsConstructor
public class FileParams {
    /**
     * 文件路径前缀
     */
    private String pathPre;

    /**
     * 文件名前缀
     */
    private String namePre;

    /**
     * 时间
     */
    private String dateStr;

    /**
     * 文件交互的时间格式，默认yyyyMMdd
     */
    private String datePatten;

    /**
     * 密码
     */
    private String password;

    /**
     * 每行对应的实体类
     */
    private Class clazz;

    /**
     * 返回的消息模板
     */
    private String resultMsg;


    /**
     * 可访问的路径    路径+文件名+文件后缀
     */
    private String pathName;


    /**
     * 根据枚举类 构建excel参数类
     *
     * @param fileEnum
     */
    public FileParams(String pathPre, FileEnum fileEnum, String dateStr, String password) {
        this.pathPre = Strings.isNotBlank(pathPre) ? pathPre : fileEnum.getPathPre();
        this.namePre = fileEnum.getNamePre();
        this.datePatten = fileEnum.getDatePatten();
        this.clazz = fileEnum.getClazz();
        this.resultMsg = fileEnum.getResultMsg();

        this.dateStr = DateUtils.changeDateStrPatten(dateStr, datePatten);
        this.password = password;
        // 文件路径前缀 + 文件名前缀 + 时间 + 文件后缀
        this.pathName = this.pathPre
                + this.namePre
                + this.dateStr
                + FileSuffer.XLSX_SUF;
    }

    /**
     * 根据枚举类 构建excel参数类
     *
     * @param fileEnum
     */
    public FileParams(String pathPre,FileEnum fileEnum, String dateStr) {
        this(pathPre, fileEnum, dateStr, null);
    }

    /**
     * 根据枚举类 构建excel参数类
     *
     * @param fileEnum
     */
    public FileParams(FileEnum fileEnum, String dateStr, String password) {
        this(null, fileEnum, dateStr, password);
    }

}
